pragma Singleton

import QtQuick
import FluentUI

FluObject{

    property var navigationView

    function rename(item, newName){
        if(newName && newName.trim().length>0){
            item.title = newName;
        }
    }
    FluPaneItem{
        id:item_home
        count: 0
        title:Lang.home
        infoBadge:FluBadge{
            count: item_home.count
        }
        icon:FluentIcons.Home
        url:"qrc:/page/HomePage.qml"
        onTap:{
            navigationView.displayMode = FluNavigationViewType.Open
            if(navigationView.getCurrentUrl()){
                item_home.count = 0
            }
            navigationView.push(url)
        }
    }

    FluPaneItemSeparator{
        spacing:10
        size:1
    }

    FluPaneItem{
        id:item_chat
        count: 0
        title:Lang.chat
        infoBadge:FluBadge{
            count: item_chat.count
        }
        icon:FluentIcons.ChatBubbles
        url:"qrc:/page/ChatPage.qml"
        onTap:{
            navigationView.displayMode = FluNavigationViewType.Compact
            if(navigationView.getCurrentUrl()){
                item_chat.count = 0
            }
            navigationView.push(url)
        }
    }

    FluPaneItem{
        id:item_member
        count: 0
        title:Lang.member
        infoBadge:FluBadge{
            count: item_member.count
        }
        icon:FluentIcons.Group
        url:"qrc:/page/MemberPage.qml"
        onTap:{
            navigationView.displayMode = FluNavigationViewType.Compact
            if(navigationView.getCurrentUrl()){
                item_member.count = 0
            }
            navigationView.push(url)
        }
    }

    FluPaneItem{
        id:item_file
        count: 0
        title:Lang.file
        infoBadge:FluBadge{
            count: item_file.count
        }
        icon:FluentIcons.FolderOpen
        url:"qrc:/page/FilePage.qml"
        onTap:{
            navigationView.displayMode = FluNavigationViewType.Compact
            if(navigationView.getCurrentUrl()){
                item_file.count = 0
            }
            navigationView.push(url)
        }
    }

    FluPaneItem{
        id:item_project
        count: 0
        title:Lang.project
        infoBadge:FluBadge{
            count: item_project.count
        }
        icon:FluentIcons.Work
        url:"qrc:/page/ProjectPage.qml"
        onTap:{
            navigationView.displayMode = FluNavigationViewType.Compact
            if(navigationView.getCurrentUrl()){
                item_project.count = 0
            }
            navigationView.push(url)
        }
    }

    FluPaneItem{
        id:item_calendar
        count: 0
        title:Lang.calendar
        infoBadge:FluBadge{
            count: item_calendar.count
        }
        icon:FluentIcons.Calendar
        url:"qrc:/page/CalendarPage.qml"
        onTap:{
            navigationView.displayMode = FluNavigationViewType.Compact
            if(navigationView.getCurrentUrl()){
                item_calendar.count = 0
            }
            navigationView.push(url)
        }
    }

    FluPaneItem{
        id:item_more
        count: 0
        title:Lang.more
        infoBadge:FluBadge{
            count: item_more.count
        }
        icon:FluentIcons.More
        url:"qrc:/page/MorePage.qml"
        onTap:{
            navigationView.displayMode = FluNavigationViewType.Compact
            if(navigationView.getCurrentUrl()){
                item_more.count = 0
            }
            navigationView.push(url)
        }
    }

    function getRecentlyAddedData(){
        var arr = []
        for(var i=0;i<children.length;i++){
            var item = children[i]
            if(item instanceof FluPaneItem && item.recentlyAdded){
                arr.push(item)
            }
            if(item instanceof FluPaneItemExpander){
                for(var j=0;j<item.children.length;j++){
                    var itemChild = item.children[j]
                    if(itemChild instanceof FluPaneItem && itemChild.recentlyAdded){
                        arr.push(itemChild)
                    }
                }
            }
        }
        arr.sort(function(o1,o2){ return o2.order-o1.order })
        return arr
    }

    function getRecentlyUpdatedData(){
        var arr = []
        var items = navigationView.getItems();
        for(var i=0;i<items.length;i++){
            var item = items[i]
            if(item instanceof FluPaneItem && item.recentlyUpdated){
                arr.push(item)
            }
        }
        return arr
    }

    function getSearchData(){
        if(!navigationView){
            return
        }
        var arr = []
        var items = navigationView.getItems();
        for(var i=0;i<items.length;i++){
            var item = items[i]
            if(item instanceof FluPaneItem){
                if (item.parent instanceof FluPaneItemExpander)
                {
                    arr.push({title:`${item.parent.title} -> ${item.title}`,key:item.key})
                }
                else
                    arr.push({title:item.title,key:item.key})
            }
        }
        return arr
    }

    function startPageByItem(data){
        navigationView.startPageByItem(data)
    }

}
